﻿using System;
using System.Linq;
using System.Collections.Generic; 
using System.Data;
using Matrix.Common.Utility;
using Matrix.MaKaYunShang.Model;
using Matrix.MaKaYunShang.DAL;

namespace Matrix.MaKaYunShang.BLL
{
	public partial class CouponCommodityLibBLL : BaseBLL<CouponCommodityLibBLL>
	{
		#region 默认方法
		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(CouponCommodityLib model)
		{
			return CouponCommodityLibDAL.Instance.Add(model);		
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(CouponCommodityLib model)
		{
			return CouponCommodityLibDAL.Instance.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int Id)
		{			
			return CouponCommodityLibDAL.Instance.Delete(Id);
		}
				/// <summary>
		/// 批量删除一批数据
		/// </summary>
		public bool DeleteList(string Idlist )
		{
			return CouponCommodityLibDAL.Instance.DeleteList(Idlist );
		}
		
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CouponCommodityLib GetModel(int Id)
		{
			var ds = CouponCommodityLibDAL.Instance.GetModel(Id);
            return ds == null ? null : ServicesHelper.DataSetToIList<CouponCommodityLib>(ds).ToList()[0];
		}
		
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<CouponCommodityLib> GetModelList(string strWhere = null)
		{
			var ds = CouponCommodityLibDAL.Instance.GetList(strWhere);
			return ServicesHelper.DataSetToIList<CouponCommodityLib>(ds).ToList();
		}
		#endregion
		
		#region 扩展方法

        public bool DeleteByCommodityLibId(int Id)
        {
            return CouponCommodityLibDAL.Instance.DeleteByCommodityLibId(Id);
        }

        /// <summary>
        /// 通过码云卡券集合获取码云卡券限制使用商品列表
        /// </summary>
        /// <param name="couponIds"></param>
        /// <returns></returns>
        public List<CouponCommodityLib> GetListByCouponIds(string couponIds)
        {
            var arrCouponId = couponIds.Split(',');
            foreach (var s in arrCouponId)
            {
                int nCouponId;
                if (!int.TryParse(s, out nCouponId))
                {
                    _fileLog.Error("CouponCommodityLibBLL | GetListByCouponIds | Invalid Commodity Ids - " +
                                   couponIds);
                    return null;
                }
            }

            return CouponCommodityLibDAL.Instance.GetListByCouponIds(couponIds);
        }
		#endregion
	}
}